package com.mall.seckil.controller;

import com.mall.common.utils.Result;
import com.mall.seckil.service.SeckillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: 谢君臣
 * @Date: 2022/9/19-20:57
 * @version: 1.0
 * @function:
 */
@Slf4j
@Controller
@RequestMapping("/seckill/kill")
public class SeckillController {

    @Resource
    private SeckillService seckillService;


    @GetMapping("/sku")
    public String killSku(@RequestParam("killId")String killId,
                          @RequestParam("key") String key,
                          @RequestParam("num") int num, Model model){
        // 判断是否登录 拦截器实现
        String orderSn = null;
        try {
            orderSn = seckillService.killSku(killId,key,num);
            model.addAttribute("orderSn",orderSn);
        } catch (RuntimeException e) {
            model.addAttribute("orderSn",null);
            model.addAttribute("message",e.getMessage());
        }
        return "success";
    }
}
